<template>
    <div>
        <a-spin :spinning="!loaded">
            <div v-if="authorized && loaded">
                <slot></slot>
            </div>
            <div v-if="!authorized" class="no-match-wrapper">
                <slot name="no-match">
                    <a-alert message="您好像没有权限访问哦~~" type="error" showIcon></a-alert>
                </slot>
            </div>
        </a-spin>
    </div>
</template>

<script>
    import Error_403 from "../pages/error/403";
    import {mapState} from 'vuex'


    export default {
        name: "Authorized",
        components: {Error_403},
        data() {
            return {

            }
        },
        computed: {

            ...mapState('admin/menu', ['authorizedMenus', 'loaded']),
            authorized() {
                let route = this.$route
                return this.authorizedMenus.some(it => {
                    return route.name == it.name;
                });
            }
        },

        methods: {}
    }
</script>

<style lang="less">
    .no-match-wrapper {
        padding: 12px;
    }
</style>
